package cn.liyunqi.ttv.web.service.impl;

import cn.liyunqi.ttv.web.bo.VersionInfo;
import cn.liyunqi.ttv.web.bo.VersionWork;
import cn.liyunqi.ttv.web.common.ResponseMap;
import cn.liyunqi.ttv.web.mapper.DictionaryMapper;
import cn.liyunqi.ttv.web.mapper.VersionInfoMapper;
import cn.liyunqi.ttv.web.mapper.VersionWorkMapper;
import cn.liyunqi.ttv.web.service.CommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 *
 */
@Transactional
@Service("commonService")
public class CommonServiceImpl implements CommonService {

    @Autowired
    private DictionaryMapper dictionaryMapper;

    @Autowired
    private VersionInfoMapper versionInfoMapper;

    @Autowired
    private VersionWorkMapper versionWorkMapper;

    @Override
    public ResponseMap<String, Object> getApiParam(ResponseMap<String, Object> responseMap) {

        String Baidu_APP_ID = dictionaryMapper.getValue(DictionaryMapper.Baidu_APP_ID,DictionaryMapper.TTS);
        String Baidu_API_KEY = dictionaryMapper.getValue(DictionaryMapper.Baidu_API_KEY,DictionaryMapper.TTS);
        String Baidu_SECRET_KEY = dictionaryMapper.getValue(DictionaryMapper.Baidu_SECRET_KEY,DictionaryMapper.TTS);
        String Kedaxunfei_APP_ID = dictionaryMapper.getValue(DictionaryMapper.Kedaxunfei_APP_ID,DictionaryMapper.TTS);


        responseMap.put("Baidu_APP_ID",Baidu_APP_ID);
        responseMap.put("Baidu_API_KEY",Baidu_API_KEY);
        responseMap.put("Baidu_SECRET_KEY",Baidu_SECRET_KEY);
        responseMap.put("Kedaxunfei_APP_ID",Kedaxunfei_APP_ID);

        return responseMap;
    }

    @Override
    public ResponseMap<String, Object> getVersion(ResponseMap<String, Object> responseMap) {

        VersionInfo vo = versionInfoMapper.selectNewVersion();

        if(vo != null){
            List<VersionWork> list = versionWorkMapper.selectByVersionId(vo.getId());
            vo.setWorkList(list);
        }

        responseMap.put("vo",vo);
        return responseMap;
    }

    @Override
    public String getDownloadZipUrl() {
        return dictionaryMapper.getValue(DictionaryMapper.Download_Zip_Url,DictionaryMapper.Download_Zip_Url);
    }
}
